<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8" />
    <title>宏宇教育信息采集</title>
    <link href="../../../css/main.css" rel="stylesheet" type="text/css" />
    <link
      href="../../../bstable/css/bootstrap.min.css"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="../../../bstable/css/bootstrap-table.css"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="../../../layer_v2.1/layer/skin/layer.css"
      rel="stylesheet"
      type="text/css"
    />
    <link href="../../../css/new.css" rel="stylesheet" type="text/css" />
  </head>

  <body>
    <!-- <div class="lx-top">
        宏宇教育信息采集
    </div> -->

    <div class="lx-section">
      <div class="title">基本信息</div>
      <div class="lx-form">
        <div class="p_line text_ient lx-row">
          <p class="col lx-col-25">
            <a class="find_a"><span style="color: red">*</span> 姓名：</a>
            <input
              id="name"
              type="text"
              maxlength="10"
              class="form_input text_ient"
            />
          </p>
          <p class="col lx-col-25">
            <a class="find_a"><span style="color: red">*</span>身份证号：</a>
            <input
              id="idno"
              type="text"
              maxlength="18"
              class="form_input text_ient"
            />
          </p>
          <p class="col lx-col-25">
            <a class="find_a">性别：</a>
            <input id="sex" type="text" class="form_input text_ient" />
          </p>
          <p class="col lx-col-25">
            <a class="find_a"><span style="color: red">*</span>电话：</a>
            <input
              id="phone"
              type="text"
              maxlength="11"
              class="form_input text_ient"
            />
          </p>
        </div>
      </div>
    </div>

    <div class="lx-section" style="display: none" id="xueli_div">
      <div class="title">学历报考信息</div>
      <div class="lx-row"></div>
    </div>

    <div class="lx-section" style="display: none" id="zhiye_div">
      <div class="title">职业报考信息</div>
      <div class="lx-row"></div>
    </div>

    <div class="lx-section" style="display: none" id="zhicheng_div">
      <div class="title">职称报考信息</div>
      <div class="lx-row"></div>
    </div>

    <div class="lx-section" style="display: none" id="peixun_div">
      <div class="title">培训报考信息</div>
      <div class="lx-row"></div>
    </div>

    <div id="xueli" style="display: none"></div>

    <div id="zhiye" style="display: none"></div>
    <div id="zhicheng" style="display: none"></div>
    <div id="peixun" style="display: none"></div>

    <div class="lx-section" id="pingzheng" style="display: none">
      <div class="title">财务凭证信息</div>
      <div class="lx-form">
        <div class="p_line text_ient lx-row ptb10">
          <div class="col lx-col-33 pz1">
            <a class="find_a">缴费凭证：</a>
            <p class="img-con" style="display: inline-block">
              <img src="" id="jiaofei" />
            </p>
          </div>
          <div class="col lx-col-33 pz1">
            <a class="find_a">优惠凭证：</a>
            <p class="img-con" style="display: inline-block">
              <img src="" id="youhui" />
            </p>
          </div>
          <div class="col lx-col-33 pz1">
            <a class="find_a">其他凭证：</a>
            <p class="img-con" style="display: inline-block">
              <img src="" id="qita" />
            </p>
          </div>
        </div>
      </div>
    </div>

    <div class="lx-section" id="bohui-info" style="display: none">
      <div class="title">驳回原因</div>
      <div class="lx-form">
        <div class="p_line text_ient lx-row">
          <p class="col lx-col-100">
            <textarea
              id="reason"
              cols="3"
              type="textarea"
              maxlength="200"
              class="form_input text_ient reason"
              placeholder="请输入原因"
            ></textarea>
          </p>
        </div>
      </div>
    </div>

    <div
      id="buttons-fenqi"
      style="display: none; text-align: center; margin-bottom: 30px"
    >
      <button class="a_add" onclick="handleSubmit()">提交</button>
    </div>

    <div class="big-img" style="display: none">
      <img src="" alt="" />
    </div>

    <script src="../../../js/jquery.js"></script>
    <script src="../../../js/common.js"></script>
    <script src="../../../layer_v2.1/layer/layer.js"></script>
    <script src="../../../bstable/js/bootstrap-table.js"></script>
    <script src="../../../bstable/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="../../../js/laydate-master/laydate.js"></script>
    <script src="./register-fenqi.js"></script>

    <script>
      function handleSubmit() {
        var data = {
          student: [window.student],
          studentEducations: [window.education],
          studentOccupations: [window.occu],
          studentTitles: [window.title],
          studentTrains: [window.train],
        };

        if (!data.studentEducations[0]) {
          delete data.studentEducations;
        }

        if (!data.studentOccupations[0]) {
          delete data.studentOccupations;
        }

        if (!data.studentTitles[0]) {
          delete data.studentTitles;
        }

        if (!data.studentTrains[0]) {
          delete data.studentTrains;
        }

        updateStudent(data, window.fees);
      }

      function updateStudent(data, fees) {
        $.ajax({
          url: baseUrl + "studentInfo/updateStudentInfo",
          method: "Post",
          contentType: "application/json;charset=UTF-8",
          data: JSON.stringify({
            ...data,
          }),
          headers: {
            Authorization: JSON.parse(localStorage.getItem("userInfo")).token,
          },
          success: function (data) {
            alert("提交成功");
            window.res = data;
            postFees(fees);
          },
          error: function (err, res, res1) {
            alert(err.responseJSON.message || "网络错误");
          },
        });
      }

      function postFees(data) {
        // fee.refundableFee(应退费用)
        // fee.deductFee(扣除费用)
        // fee.realRefundFee(实退费用)
        // fee.refundInfo(退款原因)
        // fee.payee(收款人信息)
        // fee.businessProgress(业务进度)
        const { studentId, commitBoolean } = window.res;

        data.map((item, index) => {
          // 期数
          item.stage = $(".fee").find(".fee-id").eq(index).val();
          // 缴费日期
          item.term = $(".fee").find(".fee-time").eq(index).val();
          // 缴费金额
          item.amount = $(".fee").find(".fee-money").eq(index).val();
          // 是否已缴费
          item.flag = $(".fee")
            .find(".fee-flag option:selected")
            .eq(index)
            .val();
          // 总费用
          item.allFee = $(".fee").find(".zong").eq(0).val();
          // 优惠费用
          item.preferentialFee = $(".fee").find(".youhui").eq(0).val();
          // 实缴费用
          item.realPayFee = $(".fee").find(".shijiao").eq(0).val();

          if (!item.commitBoolean) {
            item.commitBoolean = commitBoolean;
          }

          item.commitFlag = 1;
          item.businessProgress = 2;
          delete item.createDate;
        });

        $.ajax({
          url: baseUrl + "studentInfo/updateStudentFees",
          method: "post",
          headers: {
            Authorization: JSON.parse(localStorage.getItem("userInfo")).token,
          },
          contentType: "application/json",
          data: JSON.stringify(data),
          success: function (data) {
            location.href = "./paySearch.html";
          },
        });
      }

      function getQuery(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
          var pair = vars[i].split("=");
          if (pair[0] == variable) {
            return pair[1];
          }
        }
        return false;
      }

      var flag = getQuery("flag");
      var feeId = "";

      if (getQuery("from") === "student") {
        localStorage.setItem("name", "学生管理/学生信息查询/修改");
      } else if (getQuery("from") === "jiaowu") {
        localStorage.setItem("name", "教务管理/教务信息管理/修改");
      } else if (getQuery("from") === "jiaofei") {
        localStorage.setItem("name", "财务管理/缴费信息管理/修改");
      } else if (getQuery("from") === "fenqi") {
        localStorage.setItem("name", "学生管理/分期缴费信息查询/修改");
      }

      var info = {
        fileInput: $(".input-file"),
        delBtn: $(".del-img"),
        init: function () {
          this.fileChange();
          this.initDisableInput();
        },
        fileChange: function () {
          var self = this;
          this.fileInput.on("change", function () {
            var files = this.files;
            var id = $(this).attr("id");
            if (files.length) {
              id === "id-front" && self.uploadFrontImg(files[0]);
              $(this).hide();
              $(this).siblings(".img-con").css("display", "inline-block");
              self.drawImg($(this).siblings(".img-con").find("img"), files[0]);
            }
          });
        },
        enableFee() {
          $(".fee input").prop("disabled", false);
        },
        showButtons() {
          // if (getQuery('type') === 'check') {
          $("#reason").attr("disabled", false);
          $("#check-buttons").show();
          // }
        },
        drawImg: function ($el, file) {
          var URL = window.URL || window.webkitURL;
          file.fname = "123123.jpg";
          console.log(file);

          var imgUrl = URL.createObjectURL(file);
          $el.attr("src", imgUrl);
        },
        initDisableInput() {
          $("input").prop("disabled", true);
          $("select").prop("disabled", true);
          $("textarea").prop("disabled", true);
          $(".del-img").hide();
        },
      };
      info.init();

      function getUserInfo(idNo, type, studyId) {
        $.ajax({
          url: baseUrl + "studentInfo/getStudentInfo",
          method: "get",
          headers: {
            Authorization: JSON.parse(localStorage.getItem("userInfo")).token,
          },
          data: {
            idNo: idNo,
            trainType: type,
            studyId: studyId,
          },
          success: function (data) {
            if (!data.student) {
              return alert("未找到对应的数据");
            }

            var fees = data.fees;
            fees.map((item) => {
              $("#reason-info input").eq(0).val(item.refundableFee);
              $("#reason-info input").eq(1).val(item.deductFee);
              $("#reason-info input").eq(2).val(item.realRefundFee);
              $("#reason-con textarea").eq(0).val(item.refundInfo);
              $("#pay-info textarea").eq(0).val(item.payee);
            });

            // window.fees = fees;

            var student = data.student;
            // student.createDate ? delete student.createDate : ''
            // window.student = student;

            var education = data.studentEducation;
            // education && education.createDate ? delete education.createDate : ''
            // window.education = education;

            var train = data.studentTrain;
            // train && train.createDate ? delete train.createDate : ''
            // window.train = train;

            var title = data.studentTitle;
            // title && title.createDate ? delete title.createDate : ''
            // window.title = title;

            var occu = data.studentOccupation;
            // occu && occu.createDate ? delete occu.createDate : ''
            // window.occu = occu;

            if (getQuery("type") === "fenqi") {
              window.fees = fees;

              student.createDate ? delete student.createDate : "";
              window.student = student;

              education && education.createDate
                ? delete education.createDate
                : "";
              window.education = education;

              train && train.createDate ? delete train.createDate : "";
              window.train = train;

              title && title.createDate ? delete title.createDate : "";
              window.title = title;

              occu && occu.createDate ? delete occu.createDate : "";
              window.occu = occu;
            }

            // var student = data.student
            // var education = data.studentEducation
            // var train = data.studentTrain
            // var title = data.studentTitle
            // var occu = data.studentOccupation
            var id1, id2, id3, id4;
            window.uploadId = student.id;
            showImg(data.studentCards);

            if (fees[0].denyReason) {
              $("#bohui-info").show();
              $("#reason").show();
              $("#reason").val(fees[0].denyReason);
            }
            // $('#buttons-back').show();
            // education,train,title,occupation
            // 根据报考类型来查看对应的内容
            if (type == "education" && education.length !== 0) {
              var registerInfo = new RegisterInfo(type);
              var { infoDom, feeDom } = registerInfo.initLookEducations(
                education,
                fees
              );
              // 根据trainType进行对应的报考信息渲染
              $("#xueli_div").show();
              $("#xueli_div .lx-row").html(infoDom);
              $("#xueli").show();
              $("#xueli").html(feeDom);
              $("#xueli .fee").show();
            }
            // 职业
            if (type == "occupation") {
              let registerInfo = new RegisterInfo(type);
              let { infoDom, feeDom } = registerInfo.initLookOccupations(
                occu,
                fees
              );
              $("#zhiye_div").show();
              $("#zhiye_div .lx-row").html(infoDom);
              $("#zhiye").show();
              $("#zhiye").html(feeDom);
              $("#zhiye .fee").show();
            }

            if (type == "title") {
              let registerInfo = new RegisterInfo(type);
              let { infoDom, feeDom } = registerInfo.initLookTitles(
                title,
                fees
              );
              $("#zhicheng_div").show();
              $("#zhicheng_div .lx-row").html(infoDom);
              $("#zhicheng").show();
              $("#zhicheng").html(feeDom);
              $("#zhicheng .fee").show();
            }

            if (type == "train") {
              let registerInfo = new RegisterInfo(type);
              let { infoDom, feeDom } = registerInfo.initLookTrains(
                train,
                fees
              );
              $("#peixun_div").show();
              $("#peixun_div .lx-row").html(infoDom);
              $("#peixun").show();
              $("#peixun").html(feeDom);
              $("#peixun .fee").show();
            }

            info.initDisableInput();
            if (getQuery("from") !== "jiaofei") {
              info.enableFee();
            } else {
              $("#pingzheng").show();
              $("#bohui-info").show();
            }

            let from = getQuery("from");

            if (from === "fenqi") {
              $("#buttons-fenqi").show();
            } else {
              info.showButtons();
            }

            $("#name").val(student.name);
            $("#phone").val(student.phoneNum);
            $("#idno").val(student.idNo);
            $("#sex").val(student.sex);
          },
        });
      }

      function showImg(list) {
        if (!list.length) return;
        var maps = ["id-front", "id-back", "byz", "xwz"],
          maps1 = [
            "1cun",
            "2cun",
            "biyezheng1",
            "xueweizheng1",
            "zhucebiao1",
            "biyezheng2",
            "xueweizheng2",
            "zhucebiao2",
          ],
          maps2 = ["jiaofei", "youhui", "qita"],
          zh1,
          zh2,
          zh3,
          zh4,
          id;
        list.forEach(function (item, index) {
          if (maps.includes(item.property)) {
            $("#" + item.property).hide();
            $("#" + item.property)
              .siblings("p")
              .css("display", "inline-block")
              .find("img")
              .attr(
                "src",
                baseUrl +
                  "studentInfo/picDownload?url=" +
                  encodeURIComponent(item.fileResource)
              );
          } else if (maps1.includes(item.property)) {
            console.log(item);
            $("#" + item.property)
              .siblings("p")
              .css("display", "inline-block")
              .find("img")
              .attr(
                "src",
                baseUrl +
                  "studentInfo/picDownload?url=" +
                  encodeURIComponent(item.fileResource)
              );
          } else if (maps2.includes(item.property)) {
            $("#" + item.property)
              .attr(
                "src",
                baseUrl +
                  "studentInfo/picDownload?url=" +
                  encodeURIComponent(item.fileResource)
              )
              .parents(".pz1")
              .css({ display: "inline-block" });
          } else {
            console.log(zh1, 11, item);
            if (!zh1) {
              id = "zh1";
              zh1 = 1;
            } else if (!zh2) {
              id = "zh2";
              zh2 = 1;
            } else if (!zh3) {
              zh3 = 1;
              id = "zh3";
            } else {
              zh4 = 1;
              id = "zh4";
            }
            $("#" + id).hide();
            console.log(id);
            if (item.property || item.fileResource) {
              $("#" + id)
                .siblings("p")
                .css("display", "inline-block")
                .find("img")
                .attr(
                  "src",
                  baseUrl +
                    "studentInfo/picDownload?url=" +
                    encodeURIComponent(item.fileResource)
                );
              $("#" + id)
                .siblings("input")
                .val(item.property);
            }
          }
        });
      }

      var pageFrom = "";
      if (getQuery("from")) {
        var from = getQuery("from");
        var id = getQuery("id");
        var type = getQuery("type");
        var trainType = getQuery("trainType");
        var idNo = getQuery("idNo");
        var studyId = getQuery("studyId");
        pageFrom = from;

        setTimeout(() => {
          getUserInfo(idNo, trainType, studyId);
        }, 500);
      }

      function bigShow(src) {
        $(".big-img img").attr("src", src);
        $(".big-img").show();
      }
      $(".big-img").on("click", function () {
        $(".big-img").hide();
      });

      $(".img-con img").on("click", function () {
        var src = $(this).attr("src");
        if (src.endsWith("pdf")) {
          src = encodeURIComponent(location.origin + src);
          window.open("../../pdf/web/viewer.html?file=" + src);
        } else {
          bigShow(src);
        }
      });
    </script>
  </body>
</html>
